cd "C:\Users\ValentinDaurMSC\Downloads\Paper Paula & Nicole" //INSERT WORKING DIRECTORY

***********************************************************************************************************************************
********************************************Figure 1*******************************************************************************
***********************************************************************************************************************************
**** Assembly
* Evolution of defensive restrictions 
use "SD.dta", clear
collapse (sum) ass*_lib ass*_*A, by (year)
egen sum_leg = rowtotal(ass*_lib ass*_*A)
gen sum_leg1=sum_leg/(18*12)
save sum_leg.dta, replace         
 
* Evolution of illliberal restrictions
use "SD.dta", clear
collapse (sum) ass*_*N, by (year)
egen sum_ill = rowtotal(ass*_*N)
gen sum_ill1=sum_ill/(43*12)
save sum_ill.dta, replace
           
*merging
merge 1:1 year using sum_leg.dta
keep year sum_leg sum_ill sum_leg1 sum_ill1

lab var sum_leg1 "Defensive measures"
replace sum_leg1=sum_leg1*100
lab var sum_ill1 "Illiberal measures"
replace sum_ill1=sum_ill1*100

set scheme s2mono
twoway line sum_leg1 sum_ill1 year, lpattern(solid dash) xtitle("Time") ytitle("% Indicators present") title("Assembly")
graph save ass, replace

**** Expression
* Evolution of defensive restrictions 
use "SD.dta", clear
collapse (sum) expr*_lib expr*_*A, by (year)
egen sum_leg = rowtotal(expr*_lib expr*_*A)
gen sum_leg1=sum_leg/(37*12)
tab sum_leg1
save sum_leg.dta, replace         
 
* Evolution of illliberal restrictions
use "SD.dta", clear
collapse (sum) expr*_*N, by (year)
egen sum_ill = rowtotal(expr*_*N)
gen sum_ill1=sum_ill/(20*12)
tab sum_ill1
save sum_ill.dta, replace
           
*merging
merge 1:1 year using sum_leg.dta
keep year sum_leg sum_ill sum_leg1 sum_ill1

lab var sum_leg1 "Defensive measures"
replace sum_leg1=sum_leg1*100
lab var sum_ill1 "Illiberal measures"
replace sum_ill1=sum_ill1*100
twoway line sum_leg1 sum_ill1 year, lpattern(solid dash) xtitle("Time") ytitle("% Indicators present") title("Expression") 
graph save expr, replace

**** Association
* Evolution of defensive restrictions 
use "SD.dta", clear
collapse (sum) ban*_lib ban*_*A, by (year)
egen sum_leg = rowtotal(ban*_lib ban*_*A)
gen sum_leg1=sum_leg/(19*12)
tab sum_leg
save sum_leg.dta, replace         
 
* Evolution of illliberal restrictions
use "SD.dta", clear
collapse (sum) ban*_*N, by (year)
egen sum_ill = rowtotal(ban*_*N)
gen sum_ill1=sum_ill/(11*12)
save sum_ill.dta, replace
           
*merging
merge 1:1 year using sum_leg.dta
keep year sum_leg sum_ill sum_leg1 sum_ill1

lab var sum_leg1 "Defensive measures"
replace sum_leg1=sum_leg1*100
lab var sum_ill1 "Illiberal measures"
replace sum_ill1=sum_ill1*100

twoway line sum_leg1 sum_ill1 year, lpattern(solid dash) xtitle("Time") ytitle("% Indicators present") title("Association")
graph save ban, replace
*graph export "Fig1_ban.png", replace

grc1leg ass.gph expr.gph ban.gph, ycommon row (1) 
graph export "Fig1.png", replace

***********************************************************************************************************************************
********************************************Figure 2*******************************************************************************
***********************************************************************************************************************************

* Evolution of defensive restrictions 
use "SD.dta", clear
collapse (sum) *_*A *_lib, by (country year)
egen sum_leg = rowtotal(*_*A *_lib)
gen sum_leg1 = sum_leg/74
save sum_leg.dta, replace    

* Evolution of illliberal restrictions
use "SD.dta", clear
collapse (sum) *_*N, by (country year)
egen sum_ill = rowtotal(*_*N)
gen sum_ill1 = sum_ill/74
save sum_ill.dta, replace
           
*** merging the datasets
merge 1:1 country year using sum_leg.dta
keep sum_leg sum_leg1 sum_ill sum_ill1 year country
lab var sum_leg1 "Defensive measures"
replace sum_leg1=sum_leg1*100
lab var sum_ill1 "Illiberal measures"
replace sum_ill1=sum_ill1*100

*all domains lumped together
line sum_leg1 sum_ill1 year if country==1, lpattern(solid dash) xtitle("") title("AT") legend(col(3))
graph save Austria, replace
twoway line sum_leg1 sum_ill1 year if country==2, lpattern(solid dash) xtitle("") title("DE")
graph save Germany, replace
twoway line sum_leg1 sum_ill1 year if country==3, lpattern(solid dash) xtitle("") title("ES")
graph save Spain, replace
twoway line sum_leg1 sum_ill1 year if country==4, lpattern(solid dash) xtitle("") title("FR")
graph save France, replace
twoway line sum_leg1 sum_ill1 year if country==5, lpattern(solid dash) xtitle("") title("GR")
graph save Greece, replace
twoway line sum_leg1 sum_ill1 year if country==6, lpattern(solid dash) xtitle("") title("HU")
graph save Hungary, replace
twoway line sum_leg1 sum_ill1 year if country==7, lpattern(solid dash) xtitle("") title("IE")
graph save Ireland, replace
twoway line sum_leg1 sum_ill1 year if country==8, lpattern(solid dash) xtitle("") title("IT")
graph save Italy, replace
twoway line sum_leg1 sum_ill1 year if country==9,lpattern(solid dash) xtitle("") title("LV")
graph save Latvia, replace
twoway line sum_leg1 sum_ill1 year if country==10, lpattern(solid dash) xtitle("") title("MT")
graph save Malta, replace
twoway line sum_leg1 sum_ill1 year if country==11, lpattern(solid dash) xtitle("") title("PL")
graph save Poland, replace
twoway line sum_leg1 sum_ill1 year if country==12, lpattern(solid dash) xtitle("") title("UK")
graph save UK, replace

grc1leg Latvia.gph Greece.gph Hungary.gph Malta.gph Austria.gph France.gph UK.gph Spain.gph Germany.gph Poland.gph Ireland.gph Italy.gph, ycommon
graph export "Fig2.png", replace

***********************************************************************************************************************************
********************************************Figure 3*******************************************************************************
***********************************************************************************************************************************

* Against state (only assembly)
use "SD.dta", clear
br ass*_11A 
collapse (sum) ass*_11A, by (year)
egen sum_state = rowtotal(ass*_11A)
gen sum_state1= sum_state/(12*12)
save sum_state.dta, replace         

*** against process (only assembly)
use "SD.dta", clear
br ass*_12A ass*_12_lib
collapse (sum) ass*_12A ass*_12_lib, by (year)
egen sum_pro = rowtotal(ass*_12A ass*_12_lib)
gen sum_pro1=sum_pro/(3*12)
save sum_pro.dta, replace

*** against liberal values (only assembly)
use "SD.dta", clear
br ass*13_lib
collapse (sum) ass*13_lib, by (year)
egen sum_val = rowtotal(*13_lib)
gen sum_val1=sum_val/(3*12)
save sum_val.dta, replace
           
***merging
merge 1:1 year using sum_state.dta
drop _merge
merge 1:1 year using sum_pro.dta
keep year sum_state1 sum_pro1 sum_val1 

lab var sum_state1 "Harm to state"
replace sum_state1=sum_state1*100
lab var sum_pro1 "Harm to democratic process"
replace sum_pro1=sum_pro1*100
lab var sum_val1 "Harm to liberal values"
replace sum_val1=sum_val1*100

twoway line sum_state1 sum_pro1 sum_val1 year, lpattern(solid dash) xtitle("Time") ytitle("% Indicators present") title("Assembly")
graph save ass, replace

* Against state (only expression)
use "SD.dta", clear
br expr*_11A expr*11_lib
collapse (sum) expr*_11A expr*11_lib, by (year)
egen sum_state = rowtotal(expr*_11A)
gen sum_state1= sum_state/(9*12)
save sum_state.dta, replace         

*** against process (only expression)
use "SD.dta", clear
br expr*_12A expr*12_lib
collapse (sum) expr*_12A expr*12_lib, by (year)
egen sum_pro = rowtotal(expr*_12A expr*12_lib)
gen sum_pro1=sum_pro/(11*12)
save sum_pro.dta, replace

*** against liberal values (only expression)
use "SD.dta", clear
br expr*13_lib
collapse (sum) expr*13_lib, by (year)
egen sum_val = rowtotal(*13_lib)
gen sum_val1=sum_val/(17*12)
save sum_val.dta, replace
           
***merging
merge 1:1 year using sum_state.dta
drop _merge
merge 1:1 year using sum_pro.dta
keep year sum_state1 sum_pro1 sum_val1 

lab var sum_state1 "Harm to state"
replace sum_state1=sum_state1*100
lab var sum_pro1 "Harm to democratic process"
replace sum_pro1=sum_pro1*100
lab var sum_val1 "Harm to liberal values"
replace sum_val1=sum_val1*100

twoway line sum_state1 sum_pro1 sum_val1 year, lpattern(solid dash) xtitle("Time") ytitle("% Indicators present") title("Expression")
graph save expr, replace

* Against state (only association)
use "SD.dta", clear
br ban*_11A ban*11_lib
collapse (sum) ban*_11A ban*11_lib, by (year)
egen sum_state = rowtotal(ban*_11A)
gen sum_state1= sum_state/(6*12)
save sum_state.dta, replace         

*** against process (only association)
use "SD.dta", clear
br ban*_12A ban*12_lib
collapse (sum) ban*_12A ban*12_lib, by (year)
egen sum_pro = rowtotal(ban*_12A ban*12_lib)
gen sum_pro1=sum_pro/(5*12)
save sum_pro.dta, replace

*** against liberal values (only association)
use "SD.dta", clear
br ban*13_lib
collapse (sum) ban*13_lib, by (year)
egen sum_val = rowtotal(*13_lib)
gen sum_val1=sum_val/(8*12)
save sum_val.dta, replace
           
***merging
merge 1:1 year using sum_state.dta
drop _merge
merge 1:1 year using sum_pro.dta
keep year sum_state1 sum_pro1 sum_val1 

lab var sum_state1 "Harm to state"
replace sum_state1=sum_state1*100
lab var sum_pro1 "Harm to democratic process"
replace sum_pro1=sum_pro1*100
lab var sum_val1 "Harm to liberal values"
replace sum_val1=sum_val1*100
twoway line sum_state1 sum_pro1 sum_val1 year, lpattern(solid dash) xtitle("Time") ytitle("% Indicators present") title("Association")
graph save ban, replace

grc1leg ass.gph expr.gph ban.gph, ycommon row (1) 
graph export "Fig3.png", replace

*For Table 1: How many indicators do (not appear at all)?
use "SD.dta", clear
br ass*_*N
br ass*_*A ass*_lib
br expr*_*N
br expr*_*A expr*_lib
br ban*_*A ban*_lib
br ban*_*N

sum ass*_*N // 33 of 43 are present in at least one observation -> 76.74 %
sum ass*_*A ass*_lib // 17 of 18 are present in at least one observation -> 94.44 %
sum expr*_*N // 19 of 20 are present in at least one observation -> 95.00 %
sum expr*_*A expr*_lib // 31 of 37 are present in at least one observation -> 83.78 % 
sum ban*_*A ban*_lib // 17 of 19 are present in at least one observation -> 89.47 %
sum ban*_*N // 11 of 11 are present in at least one observation -> 89.47 %
* All/Assembly: 50 of 61 are present in at least one observation -> 81.97 %
* All/Expression: 50 of 57 are present in at least one observation -> 87.72 %
* All/Expression: 28 of 30 are present in at least one observation -> 93.33 %
* Total/Defensive: (17+31+17)/74 = 87.84%
* Total/Illiberal: (33+19+11)/74 = 85.14%
* Total/All: (17+31+17+33+19+11)/148 = 86.49%